package com.example.cim.init;

import com.example.cim.util.SpringBeanFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Function:
 *
 * @author crossoverJie
 *         Date: 2018/8/24 01:37
 * @since JDK 1.8
 */
public class RegistryZK implements Runnable {
    private static Logger logger = LoggerFactory.getLogger(RegistryZK.class);

    private ZKit zKit;
    private String ip;
    private String websocketPort;
    private String appPort;
    private String httpPort;

    public RegistryZK(String ip, String websocketPort,String appPort,String httpPort) {
        this.ip = ip;
        this.websocketPort = websocketPort;
        this.appPort = appPort;
        this.httpPort = httpPort ;
        zKit = SpringBeanFactory.getBean(ZKit.class) ;
    }

    @Override
    public void run() {
        //创建父节点
        zKit.createRootNode();
        //是否要将自己注册到 ZK
        String path = "/server" + "/ip-" + ip + ":" + websocketPort + ":" + appPort + ":" + httpPort;
        zKit.createNode(path);
        logger.info("Registry zookeeper success, msg=[{}]", path);
    }
}